package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime"
	"strings"
)

func getOSVersion() (map[string]string, error) {
	file, err := os.Open("/etc/os-release")
	if err != nil {
		return nil, err
	}
	defer file.Close()

	info := make(map[string]string)
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		line := scanner.Text()
		parts := strings.SplitN(line, "=", 2)
		if len(parts) == 2 {
			key := parts[0]
			value := strings.Trim(parts[1], "\"")
			info[key] = value
		}
	}

	if err := scanner.Err(); err != nil {
		return nil, err
	}
	return info, nil
}

func main() {
	if runtime.GOOS == "windows" {
		fmt.Println("当前系统是Windows系统，无法通过读取 /etc/os-release 文件来获取版本信息。")
		return
	}
	info, err := getOSVersion()
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	fmt.Printf("Name: %s\n", info["NAME"])
	fmt.Printf("Version: %s\n", info["VERSION"])
}
